package com.taijihuabao.common.activititasklistener.expensetasklistener;

import com.taijihuabao.modules.entity.DeptUserEntity;
import com.taijihuabao.modules.mapper.DeptUserMapper;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @title: AllDeptListener
 * @Author luoxianan
 * @Date: 2021/12/30 9:53
 * @Version 1.0
 */
@Component
public class AllDeptListener implements TaskListener {
    /**
     * 财务部编码
     */
    private final String DEPTCODE = "2021121408";
    /**
     * 主管
     */
    private final String ADMINISTRATOR = "administrator";
    /**
     * 审核员
     */
    private final String ASSESSOR = "assessor";
    private final String  TEXT= "财务部门审批";
    private final String TYPE= "create";
    @Autowired
    private DeptUserMapper deptUserMapper;
    @Override
    public void notify(DelegateTask delegateTask) {
        if (TEXT.equals(delegateTask.getName()) && TYPE.equals(delegateTask.getEventName())) {
            //查询部门
            List<DeptUserEntity> deptUserEntitys = deptUserMapper.selectDeptByDeptCode(DEPTCODE);
            //根据部门和id查询角色
            for (DeptUserEntity due : deptUserEntitys) {
                if (ADMINISTRATOR.equals(due.getDeptRole()) || ASSESSOR.equals(due.getDeptRole())) {
                    delegateTask.addCandidateUser(String.valueOf(due.getUserId()));
                }
            }

        }
    }
}
